/*
	FileName : app_led.c
	Description : 
	
	Created on 2013.10.27 by ZZP.
	
	Revision History:
	
*/

#include "bsp.h"
#include "app.h"
#include "app_led.h"


void LedHandler(void)
{
	//LED_WORK => off : on = 0.618 : 0.382
    if ((AppInfo.WRKLedTm % 100)   == 0)
    {
        BSP_LED_Off(LED_WRK);
		AppInfo.WRKLedTm = 0;
    }
    else if (AppInfo.WRKLedTm == 55)
   	{
   		BSP_LED_On(LED_WRK);
	}
    else if (AppInfo.WRKLedTm == 50)
   	{
   		BSP_LED_Off(LED_WRK);
	}
    else if (AppInfo.WRKLedTm == 17)
   	{
   		BSP_LED_On(LED_WRK);
	}
    else if (AppInfo.WRKLedTm == 12)
   	{
   		BSP_LED_Off(LED_WRK);
	}
    else if (AppInfo.WRKLedTm == 7)
   	{
   		BSP_LED_On(LED_WRK);
	}
	AppInfo.WRKLedTm++;

	
	//LED_PWR => off : on = 0.618 : 0.382
    if ((AppInfo.PWRLedTm % 500)   == 0)
    {
        BSP_LED_On(LED_PWR);
		AppInfo.PWRLedTm = 0;
    }
    else if ((AppInfo.PWRLedTm % 15) == 0)
   	{
   		BSP_LED_On(LED_PWR);
	}
	AppInfo.PWRLedTm++;

	
	///LED_NET
	if (AppInfo.NetRxFlag)
	{	
		if (AppInfo.NETLedTm >= 16)
		{	
			BSP_LED_Off(LED_NET);
			
			AppInfo.NETLedTm = 0;
			
			AppInfo.NetRxFlag--;
		}
		else
		{	
			if ((AppInfo.NETLedTm % 8) == 0)
			{
				BSP_LED_On(LED_NET);
			}
			else if ((AppInfo.NETLedTm % 4) == 0)
			{
				 BSP_LED_Off(LED_NET);
			}
			
			AppInfo.NETLedTm++;
		}
	}
	else
	{
		BSP_LED_Off(LED_NET);
		AppInfo.NETLedTm = 0;
	}

	///LED_COM
	if (AppInfo.UsartRxFlag[COM1])
	{	
		if (AppInfo.COMLedTm >= 16)
		{	
			BSP_LED_Off(LED_COM);
			AppInfo.COMLedTm = 0;
			AppInfo.UsartRxFlag[COM1]--;
		}
		else
		{	
			if ((AppInfo.COMLedTm % 8) == 0)
			{
				BSP_LED_On(LED_COM);
			}
			else if ((AppInfo.COMLedTm % 4) == 0)
			{
			    BSP_LED_Off(LED_COM);
			}
			
			AppInfo.COMLedTm++;
		}
	}
	else
	{
		BSP_LED_Off(LED_COM);
		AppInfo.COMLedTm = 0;
	}
	
}





